def isPrime(v):
    if v == 1: return False
    b = True
    l = v - 1
    while l > 1:
        if not v % l:
            b = False
            break
        l -= 1
    return b

s = input()
r =[]
for i in range(len(s)):
    for l in range(i + 1,len(s) +  1):
        v = int (s[i:l])
        if isPrime(v):
            r += [v]
print(max(r) if r else 0)
